package com.example.algorithm.hash;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author : zhy
 * @since : 2022/7/24
 * 两数和
 */
public class CountAdd {

    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int len=nums.length;
        for(int i=0;i<len;i++)
        {
            if(map.containsKey(target-nums[i]))
            {
                Integer first = map.get(target - nums[i]);
                return new int[]{first,i};
            }
            map.put(nums[i],i);
        }
        return new int[]{};

    }

    public static void main(String[] args) {

    }
}
